package com.example;

import java.util.Arrays;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @author Create By Liuqz
 * @date 2018/11/15 11:31
 */
public class MethodReference {

    public static void main(String[] args) {
//        Consumer<String> consumer = (s -> System.out.println(s));
//        userConsumer(consumer,"Hello Consumer");

//        userConsumer(s -> System.out.println(s),"Hello Consumer");
//        userConsumer(System.out::println,"Hello Consumer");

//        List<Apple> apples = Arrays.asList(new Apple("red", 120), new Apple("yellow", 150), new Apple("abc", 123));
//        apples.sort((a1,a2) -> a1.getColor().compareTo(a2.getColor()));
//        System.out.println(apples);
//        System.out.println("====================================");
//        apples.stream().forEach(System.out::println);

//        Function<String,Integer> f = Integer::parseInt;
//        System.out.println(f.apply("123"));

//        BiFunction<String, Integer, Character> f = String::charAt;
//        System.out.println(f.apply("123abc",3));

//        Supplier<String> supplier = String::new;
//        System.out.println(supplier.get());

        BiFunction<String,Integer,Apple> f = Apple::new;
        System.out.println(f.apply("red",234));

    }

    private static <T> void userConsumer(Consumer consumer, T t) {
        consumer.accept(t);
        consumer.accept(t);
    }
}
